package com.pay.controller.admin;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.github.pagehelper.PageInfo;
import com.pay.common.base.BaseController;
import com.pay.common.domain.AjaxResult;
import com.pay.model.auto.OmniTransactionRes;
import com.pay.model.custom.TableSplitResult;
import com.pay.model.custom.Tablepar;
import com.pay.model.custom.TitleVo;
import com.pay.service.OmniTransactionResService;
import io.swagger.annotations.Api;

@Controller
@RequestMapping("OmniTransactionResController")
@Api(value = "omni交易事务")
public class OmniTransactionResController extends BaseController {

    private String prefix = "admin/omniTransactionRes";
    @Autowired
    private OmniTransactionResService omniTransactionResService;

    @GetMapping("view")
    @RequiresPermissions("gen:omniTransactionRes:view")
    public String view(Model model) {
        String str = "omni交易事务";
        setTitle(model, new TitleVo("列表", str + "管理", true, "欢迎进入" + str + "页面", true, false));
        return prefix + "/list";
    }


    @PostMapping("list")
    @RequiresPermissions("gen:omniTransactionRes:list")
    @ResponseBody
    public Object list(Tablepar tablepar, String searchTxt) {
        PageInfo<OmniTransactionRes> page = omniTransactionResService.list(tablepar, searchTxt);
        TableSplitResult<OmniTransactionRes> result = new TableSplitResult<OmniTransactionRes>(page.getPageNum(), page.getTotal(), page.getList());
        return result;
    }

    /**
     * 充值记录
     * @return
     * @throws Exception
     */
    @PostMapping("updateWalletAndTransactions")
    @RequiresPermissions("gen:omniTransactionRes:wallet")
    @ResponseBody
    public Object updateWalletAndTransactions() throws Exception {
        omniTransactionResService.updateWalletAndTransactions();
        return success();
    }

    /**
     * 新增
     */
    @GetMapping("/add")
    public String add(ModelMap modelMap) {
        return prefix + "/add";
    }


    @PostMapping("add")
    @RequiresPermissions("gen:omniTransactionRes:add")
    @ResponseBody
    public AjaxResult add(OmniTransactionRes omniTransactionRes, Model model) {
        int b = omniTransactionResService.insertSelective(omniTransactionRes);
        if (b > 0) {
            return success();
        } else {
            return error();
        }
    }

    /**
     * 删除用户
     * @param ids
     * @return
     */
    @PostMapping("remove")
    @RequiresPermissions("gen:omniTransactionRes:remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        int b = omniTransactionResService.deleteByPrimaryKey(ids);
        if (b > 0) {
            return success();
        } else {
            return error();
        }
    }

    /**
     * 检查用户
     * @param tsysUser
     * @return
     */
    @PostMapping("checkNameUnique")
    @ResponseBody
    public int checkNameUnique(OmniTransactionRes omniTransactionRes) {
        int b = omniTransactionResService.checkNameUnique(omniTransactionRes);
        if (b > 0) {
            return 1;
        } else {
            return 0;
        }
    }


    /**
     * 修改跳转
     * @param id
     * @param mmap
     * @return
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap) {
        mmap.put("OmniTransactionRes", omniTransactionResService.selectByPrimaryKey(id));

        return prefix + "/edit";
    }

    /**
     * 修改保存
     */
    @RequiresPermissions("gen:omniTransactionRes:edit")
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(OmniTransactionRes record) {
        return toAjax(omniTransactionResService.updateByPrimaryKeySelective(record));
    }


}
